package com.zheng.redpacket.server.utils.consumer;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * 基本消息模型(消费者)
 */
@Component
public class BasicConsumer {
    private static final Logger LOGGER = LoggerFactory.getLogger(BasicConsumer.class);
    @Autowired
    private ObjectMapper objectMapper;

    @RabbitListener(queues = "${mq.basic.info.queue.name}", containerFactory = "singleListenerContainer")
    public void consumeMsg (@Payload byte[] msg) {
        try {
            String message = new String(msg, "utf-8");
            LOGGER.info("消费者-监听到消息：{}",message);
        } catch (Exception e) {
            LOGGER.error("消费者-监听消息异常：",e.fillInStackTrace());
        }
    }
}
